{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<script>
    function no_pic(obj) {
        obj.setAttribute("src", "/Public/Images/acp/nopicture.jpg");
    }
</script>

<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">用户名称：</span>
            <input type="text" name="user_name" value="{$user_name}">

            <span class="tbs-txt">联系方式：</span>
            <input type="text" name="mobile" value="{$mobile}">

            <div class="mgt10">
                <span class="tbs-txt">申请时间：</span>
                <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd H:mm'})">
                <span class="tbs-txt">至</span>
                <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd H:mm'})">
                <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
            </div>

        </form>
    </div>
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
            <col width="5%">
            <col width="8%">
            <col width="8%">
            <col width="10%">
            <col width="15%">
            <col width="10%">
            <col width="10%">
            <col width="10%">
            <col width="6%">
            <col width="20%">
        </colgroup>
        <thead>
        <tr>
            <td>选择</td>
            <td>用户名</td>
            <td>联系方式</td>
            <td>公司名称</td>
            <td>服务描述</td>
            <td>备注</td>
            <td>服务商/导师</td>
            <td>添加时间</td>
            <td>服务状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {foreach from=$service_apply_list item=item name=list}
        <tr>
            <td><input type="checkbox" class="checkbox" value="{$item.service_apply_id}" name="a[]"></td>
            <td>{$item.user_name}</td>
            <td>{$item.mobile}</td>
            <td>{$item.company_name}</td>
            <td>{$item.service_sketch}</td>
            <td>{$item.remark}</td>
            <td>{$item.their_name}</td>
            <td>{$item.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</td>
            <td>{$item.status}</td>
            <td>

                <a href="javascript:;" class="btn" onclick="set_apply_status({$item.service_apply_id})">修改状态</a>
                {if $item.service_type_id != 1}
                    {if $item.service_type == 0}
                        <a href="/AcpServiceProviders/get_all_service_providers_list/service_providers_id/{$item.service_providers_id}" class="btn" title="查看服务商">查看服务商</a>
                    {else}
                        <a href="/AcpServiceProviders/get_mentor_list/service_providers_id/{$item.service_providers_id}" class="btn" title="查看导师">查看导师</a>
                    {/if}
                {/if}
                <a href="javascript:;" class="btn" onclick="delete_obj({$item.service_apply_id})">删除服务</a>
            </td>
        </tr>
        {foreachelse}
        <tr><td colspan="10">没有找到任何记录</td></tr>
        {/foreach}
        </tbody>
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <div class="fl">
            <a href="javascript:Select()" class="btn btn-blue">全选</a>
            <a href="javascript:Cancel()" class="btn btn-blue">取消</a>
            <a href="javascript:;" class="btn btn-blue " onclick="batch_delete_obj()">删除</a>
        </div>
        <div class="fr">
            <div class="paginate">
                {$page_str}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__ACPJS__/acp_item.js?version={$version}"></script>
<script src="__JS__/front/jquery.showLoading.min.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<link rel="stylesheet" href="__CSS__/front/showLoading.css?version={$version}">
{literal}
<script>
    //全选
    function Select(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=true;
        }
    }
    //取消全选
    function Cancel(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=false;
        }
    }

</script>
<script>
    function set_apply_status(obj_id)
    {
        var html='';

        var html='<form id="deliver_form">' +
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>选择状态：</label>'+
                '<div class="form-controls">'+
                '<select class="small" name="apply_status" id="apply_status">'+
                {/literal}
        '<option value="">--选择状态--</option>'+
        {foreach from=$apply_status_arr key=key item=item}
        '<option value="{$key}">{$item}</option>'+
        {/foreach}
        {literal}
        '<input type="hidden" name="obj_id" value="'+obj_id+'">'+
        '</div>'+
        '</form>';

        $.jPops.custom({
            title:"操作",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {
                    $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpServiceApply/set_apply_status',$('#deliver_form').serialize(),function(data)
                                    {
                                        if (data.code==1)
                                        {
                                            alert(data.msg);
                                            location.reload();
                                        }
                                        else
                                        {
                                            alert(data.msg);
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });

                    //表单验证规则
                    $("#deliver_form").validate(
                            {
                                rules:
                                {
                                    apply_status:
                                    {
                                        required: true
                                    },

                                },
                                messages:
                                {
                                    apply_status:
                                    {
                                        required: "对不起，请选择状态"
                                    },

                                },
                                errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                            });

                    //模拟提交表单
                    $("#deliver_form").submit();
                    return acp.batchDeliverFormStatus;
                }
                else
                {
                    return true;
                }
            }
        });
    }



    function delete_obj(obj_id)
    {
        $.jPops.confirm(
                {
                    title:"提示",
                    content:"您确定要删除这条数据吗？",
                    okBtnTxt:"确定",
                    cancelBtnTxt:"取消",
                    callback:function(r)
                    {
                        if(r)
                        {
                            $.post('/AcpServiceApply/delete_service_apply', {"obj_id":obj_id}, function(data, textStatus)
                            {
                                if (data == 'success')
                                {
                                    alert('恭喜您，删除成功！');
                                    location.reload();
                                }
                                else
                                {
                                    alert('对不起，删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }

    function batch_delete_obj()
    {
        $.jPops.confirm(
                {
                    title:"提示",
                    content:"您确定要删除这些数据吗？",
                    okBtnTxt:"确定",
                    cancelBtnTxt:"取消",
                    callback:function(r)
                    {
                        if(r)
                        {
                            var obj_ids = '';
                            var count = 0;
                            $('input[name="a[]"]:checked').each(function(){
                                count ++;
                                obj_ids += $(this).val() + ',';
                            });

                            if (!count)
                            {
                                alert('对不起，请选择至少一项进行删除！');
                                return;
                            }

                            obj_ids = obj_ids.substr(0, obj_ids.length - 1);

                            $.post('/AcpServiceApply/batch_delete_service_apply', {"obj_ids":obj_ids}, function(data, textStatus)
                            {
                                if (data == 'success')
                                {
                                    alert('恭喜您，删除成功！');
                                    location.reload();
                                }
                                else
                                {
                                    alert('对不起，删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }
</script>
{/literal}
{/block}
